package com.yanqu.road.entity.player;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_comb_leader", desc = "组合头目")
public class UserCombLeaderData extends DataObject {

	@FieldTypeAnnotation(select = true, update = true, desc = "玩家id")
	private long userId;
	@FieldTypeAnnotation(desc = "组合id", update = true)
	private int combId;
	@FieldTypeAnnotation(desc = "当前头目")
	private int leaderId;
	@FieldTypeAnnotation(desc = "晋升id")
	private int promoteId;
	@FieldTypeAnnotation(desc = "上次选择时间")
	private long lastChooseTime;
	@FieldTypeAnnotation(desc = "羁绊的门客id")
	private int keepSakePatronsId;
	@FieldTypeAnnotation(desc = "羁绊的时间/秒")
	private long keepSakeTime;
	@FieldTypeAnnotation(desc = "头目技能养成")
	private Map<Integer, CombLeaderSkill> skillMap = new ConcurrentHashMap<>();

	public UserCombLeaderData() {
	}

	public UserCombLeaderData(long userId, int combId) {
		this.userId = userId;
		this.combId = combId;
		setInsertOption();
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public int getCombId() {
		return combId;
	}

	public void setCombId(int combId) {
		this.combId = combId;
	}

	public int getLeaderId() {
		return leaderId;
	}

	public void setLeaderId(int leaderId) {
		this.leaderId = leaderId;
		setUpdateOption();
	}

	public int getPromoteId() {
		return promoteId;
	}

	public void setPromoteId(int promoteId) {
		this.promoteId = promoteId;
		setUpdateOption();
	}

	public long getLastChooseTime() {
		return lastChooseTime;
	}

	public void setLastChooseTime(long lastChooseTime) {
		this.lastChooseTime = lastChooseTime;
		setUpdateOption();
	}

	public Map<Integer, CombLeaderSkill> getSkillMap() {
		return skillMap;
	}

	public void setSkillMap(Map<Integer, CombLeaderSkill> skillMap) {
		this.skillMap = skillMap;
	}

	public int getSkillLv(int skillId) {
		CombLeaderSkill combLeaderSkill = skillMap.get(skillId);
		if (combLeaderSkill == null) {
			return 0;
		}
		return combLeaderSkill.getLv();
	}

	public void addSkillLv(int skillId, int times) {
		CombLeaderSkill combLeaderSkill = skillMap.get(skillId);
		if (combLeaderSkill == null) {
			combLeaderSkill = new CombLeaderSkill();
			combLeaderSkill.setId(skillId);
			skillMap.put(skillId, combLeaderSkill);
		}
		combLeaderSkill.setLv(combLeaderSkill.getLv() + times);
		setUpdateOption();
	}

	public void setSkillLv(int skillId, int lv) {
		CombLeaderSkill combLeaderSkill = skillMap.get(skillId);
		if (combLeaderSkill == null) {
			combLeaderSkill = new CombLeaderSkill();
			combLeaderSkill.setId(skillId);
			skillMap.put(skillId, combLeaderSkill);
		}
		combLeaderSkill.setLv(lv);
		setUpdateOption();
	}

	public int getKeepSakePatronsId() {
		return keepSakePatronsId;
	}

	public void setKeepSakePatronsId(int keepSakePatronsId) {
		this.keepSakePatronsId = keepSakePatronsId;
	}

	public long getKeepSakeTime() {
		return keepSakeTime;
	}

	public void setKeepSakeTime(long keepSakeTime) {
		this.keepSakeTime = keepSakeTime;
		setUpdateOption();
	}
}
